<!DOCTYPE html>
<html lang="en">
<head>

</head>
<body>
<div class="ares-clearfix">
    <span class="ares-mr-lg">患者总数: <b id='patient-sums-count'></b></span>
    <span>新增患者总数: <b id='new-patient-sums-count'></b></span>
    <input class="ares-float-right layui-input ares-w-auto" readonly id="tendency-date" placeholder=" - ">
</div>
<div class="ares-row">
    <div id="tendency-echart1" class="ares-col-md-6 echart"></div>
    <div id="tendency-echart2" class="ares-col-md-6 echart"></div>
</div>

<script>
    $(function ($) {
        var defaultStartTime = +new Date().setMonth(new Date().getMonth() - 1),
            defaultEndTime = +new Date();

        laydate.render({
            elem: '#tendency-date',
            btns: [ 'confirm'],
            range: true,
            value: dateFilters.dateFormat(defaultStartTime) + ' - ' + dateFilters.dateFormat(defaultEndTime),
            done: function (value, date, endDate) {
                var range = value.split(' - ');
                tendencyCountPie(+new Date(range[0]), +new Date(range[1]));
            }
        });

        function tendencyCountPie(startTime, endTime) {
            mandyServices.mandy_statistic_new_patient(startTime, endTime).then(function (res) {
                var data = res.data;
                console.log("++++++++++质控统计整体趋势饼图++++++++++")
                console.log(data)
                console.log("++++++++++质控统计整体趋势饼图++++++++++")
                $("#patient-sums-count").text(data.map.sum.sumsCount + "人")
                $("#new-patient-sums-count").text(data.map.sum.newPatientsCount + "人")
                var t1 = "按治疗组",
                    t2 = "按患者类别";
                var c1 = ['#33CC66', '#3399FF', '#FF0000', '#9966CC', 'pink'],
                    c2 = ['#33CC66', '#3399FF', '#FF0000'];
                var n1 = data.map.new_patient_by_group.name;
                var val1 = data.map.new_patient_by_group.value;
                var i;
                var v1 = [];
                for (i = 0; i < n1.length; i++) {
                    v1[i] = {};
                    v1[i].value = val1[i];
                    v1[i].name = n1[i];
                }
                var n2 = data.map.new_patient_by_disease.name;
                var val2 = data.map.new_patient_by_disease.value;
                var j;
                var v2 = [];
                for (j = 0; j < n2.length; j++) {
                    v2[j] = {};
                    v2[j].value = val2[j];
                    if (n2[j] == 0) {
                        v2[j].name = "神经康复";
                        n2[j] = "神经康复";
                    } else if (n2[j] == 1) {
                        v2[j].name = "骨科康复";
                        n2[j] = "骨科康复";
                    } else {
                        v2[j].name = "其它";
                        n2[j] = "其它";
                    }

                }

                option1 = setTab1Option(t1, n1, v1, c1);
                option2 = setTab1Option(t2, n2, v2, c2);

                var tendencyEchart1 = echarts.init($("#tendency-echart1")[0]);
                var tendencyEchart2 = echarts.init($("#tendency-echart2")[0]);

                tendencyEchart1.setOption(option1);
                tendencyEchart2.setOption(option2);

            }, function (err) {
                console.log(err)
            })
        }

        tendencyCountPie(defaultStartTime, defaultEndTime);
    })
</script>
</body>
</html>